package com.grapecc.springcloud.controller;

import com.grapecc.springcloud.entities.CommonResult;
import com.grapecc.springcloud.entities.Payment;
import com.grapecc.springcloud.service.PaymentHystrixService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 卖糖的兜兜
 * @version 1.0.0
 * @ClassName PaymentHystrixController.java
 * @Description TODO
 * @createTime 2022年02月14日 13:20:00
 */
@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_global_fallbackMethod") ///标注通用的   已经指明的就使用指明得
public class PaymentHystrixController {
    @Resource
    private PaymentHystrixService baseService;

    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id){
        String s = baseService.payment_oK(id);
        return s;
    }

    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
//    @HystrixCommand(fallbackMethod = "payment_timeoutHandler",commandProperties = {
//            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="1500")
//    })
    @HystrixCommand
    public String paymentFeignTimeout(@PathVariable("id") Integer id){
        int  num = 10/0;
        String s = baseService.payment_timeout(id);
        return s;
    }
    public String payment_timeoutHandler(Integer id){
        return  "线程池:"+Thread.currentThread().getName()+"payment_timeoutHandler_id："+id+"耗时时间为超过5min";
    }

    public String payment_global_fallbackMethod(){
        return  "线程池:当前兜底方案为默认";
    }
}
